package com.ruoyi.information.controller.back;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.information.domain.back.SysUserNeedBack;
import com.ruoyi.information.service.back.ISysUserNeedBackService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 需求方Controller
 *
 * @author ruoyi
 * @date 2023-05-08
 */
@RestController
@RequestMapping("/userNeedBack")
public class SysUserNeedBackController extends BaseController
{
    @Autowired
    private ISysUserNeedBackService sysUserNeedService;

    /**
     * 查询需求方列表
     */
    @RequiresPermissions("information:userNeed:list")
    @GetMapping("/list")
    public TableDataInfo list(SysUserNeedBack sysUserNeed)
    {
        startPage();
        List<SysUserNeedBack> list = sysUserNeedService.selectSysUserNeedList(sysUserNeed);
        return getDataTable(list);
    }

    /**
     * 导出需求方列表
     */
    @RequiresPermissions("information:userNeed:export")
    @Log(title = "需求方", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysUserNeedBack sysUserNeed)
    {
        List<SysUserNeedBack> list = sysUserNeedService.selectSysUserNeedList(sysUserNeed);
        ExcelUtil<SysUserNeedBack> util = new ExcelUtil<SysUserNeedBack>(SysUserNeedBack.class);
        util.exportExcel(response, list, "需求方数据");
    }

    /**
     * 获取需求方详细信息
     */
    @RequiresPermissions("information:userNeed:query")
    @GetMapping(value = "/{userId}")
    public AjaxResult getInfo(@PathVariable("userId") Long userId)
    {
        return success(sysUserNeedService.selectSysUserNeedByUserId(userId));
    }

    /**
     * 新增需求方
     */
    @RequiresPermissions("information:userNeed:add")
    @Log(title = "需求方", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysUserNeedBack sysUserNeed)
    {
        return toAjax(sysUserNeedService.insertSysUserNeed(sysUserNeed));
    }

    /**
     * 修改需求方
     */
    @RequiresPermissions("information:userNeed:edit")
    @Log(title = "需求方", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysUserNeedBack sysUserNeed)
    {
        return toAjax(sysUserNeedService.updateSysUserNeed(sysUserNeed));
    }

    /**
     * 删除需求方
     */
    @RequiresPermissions("information:userNeed:remove")
    @Log(title = "需求方", businessType = BusinessType.DELETE)
	@DeleteMapping("/{userIds}")
    public AjaxResult remove(@PathVariable Long[] userIds)
    {
        return toAjax(sysUserNeedService.deleteSysUserNeedByUserIds(userIds));
    }
}
